package com.letian.web.controller.record;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.letian.common.annotation.Log;
import com.letian.common.core.controller.BaseController;
import com.letian.common.core.domain.AjaxResult;
import com.letian.common.enums.BusinessType;
import com.letian.record.domain.RecordNote;
import com.letian.record.service.IRecordNoteService;
import com.letian.common.utils.poi.ExcelUtil;
import com.letian.common.core.page.TableDataInfo;

/**
 * 记录日记Controller
 * 
 * @author bmz
 * @date 2023-09-28
 */
@RestController
@RequestMapping("/record/note")
public class RecordNoteController extends BaseController
{
    @Autowired
    private IRecordNoteService recordNoteService;

    /**
     * 查询记录日记列表
     */
    @PreAuthorize("@ss.hasPermi('record:note:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordNote recordNote)
    {
        startPage();
        List<RecordNote> list = recordNoteService.selectRecordNoteList(recordNote);
        return getDataTable(list);
    }

    /**
     * 导出记录日记列表
     */
    @PreAuthorize("@ss.hasPermi('record:note:export')")
    @Log(title = "记录日记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordNote recordNote)
    {
        List<RecordNote> list = recordNoteService.selectRecordNoteList(recordNote);
        ExcelUtil<RecordNote> util = new ExcelUtil<RecordNote>(RecordNote.class);
        util.exportExcel(response, list, "记录日记数据");
    }

    /**
     * 获取记录日记详细信息
     */
    @PreAuthorize("@ss.hasPermi('record:note:query')")
    @GetMapping(value = "/{noteId}")
    public AjaxResult getInfo(@PathVariable("noteId") Long noteId)
    {
        return success(recordNoteService.selectRecordNoteByNoteId(noteId));
    }

    /**
     * 新增记录日记
     */
    @PreAuthorize("@ss.hasPermi('record:note:add')")
    @Log(title = "记录日记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordNote recordNote)
    {
        recordNote.setOwner(getUsername());
        recordNote.setCreateBy(getUsername());
        return toAjax(recordNoteService.insertRecordNote(recordNote));
    }

    /**
     * 修改记录日记
     */
    @PreAuthorize("@ss.hasPermi('record:note:edit')")
    @Log(title = "记录日记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordNote recordNote)
    {
        recordNote.setUpdateBy(getUsername());
        return toAjax(recordNoteService.updateRecordNote(recordNote));
    }

    /**
     * 删除记录日记
     */
    @PreAuthorize("@ss.hasPermi('record:note:remove')")
    @Log(title = "记录日记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{noteIds}")
    public AjaxResult remove(@PathVariable Long[] noteIds)
    {
        return toAjax(recordNoteService.deleteRecordNoteByNoteIds(noteIds));
    }
}
